
import { routerRedux } from 'dva/router';
import { stringify } from 'qs';
import { getHomeAnalysisDataPost,getXcxScanNums } from '@/services/http';
import { setValueWithLocalStorage } from '@/utils/authority';

export default {
  namespace : 'dashboardhome',
  state:{
    ayalysisData:{},
    xcxScanTotalNum:0,
    xcxScanTodayNum:0,
  },

  effects: {
    *getHomeAnalysisData(payload, { call, put }) {
      const response = yield call(getHomeAnalysisDataPost,payload.payload);
      yield put({
        type: '_getHomeAnalysisData',
        ayalysisData: response,
      });
    },

    *getXcxScanNums(payload, { call, put }) {
      const response = yield call(getXcxScanNums,payload.payload);
      if(response.code == -1000){
        yield put(
          routerRedux.push({
            pathname: '/user/login',
            search: stringify({
              redirect: window.location.href,
            }),
          })
        );
      }else {
        yield put({
          type: '_getXcxScanNums',
          data: response,
        });
      }
    },

  },

  reducers:{
    _getHomeAnalysisData(state,action){
      return {
        ...state,
        ayalysisData: action.ayalysisData,
      }
    },

    _getXcxScanNums(state,action){
      return {
        ...state,
        xcxScanTotalNum: action.data.ret.xcxScanTotalNum,
        xcxScanTodayNum: action.data.ret.xcxScanTodayNum,
      }
    },

  }

}
